<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/** 
 *  Cpanel Class  
 *  
 * @package XGO CMS v2.0 
 * @subpackage News  
 * @author Manh Nguyen - 30/07/2012 
 * @link http://sunsoft.vn
 */
class Cpanel extends CI_Controller{
	/** 
	 * Contrust class
	 *  
	 * @access public 
	 */
	public function __construct(){
		parent::__construct();		
		$this->load->library('smarty3', '', 'smarty');
		require_once(APPPATH . 'modules/backend/autoload.php');        
        
        $this->load->library('login_manager', array('autologin' => FALSE));
	}	
	
	public function index(){
		if(!empty($_POST)){
			$user = $this->login_manager->get_user();
			if($user !== FALSE)
			{
				redirect('home');
			}
			
			$user = new User_model();
			$user->username = $this->input->post('username');
			$user->password = $this->input->post('password');
			
			if(!empty($user->username) && !empty($user->password))
			{
				$login_redirect = $this->login_manager->process_login($user);
				if($login_redirect)
				{
					if($login_redirect != TRUE){
						redirect($login_redirect);
					}
					redirect($this->router->directory);
				}
				$this->session->set_flashdata('message', $user->error->string);
			}else{
				$this->session->set_flashdata('message', $this->lang->line('input_empty'));
			}
		}
		redirect('auth/cpanel/login');
	}
	
	public function dashboard() {
		$this->smarty->display('template/backend/dashboard');
	}
	
	public function login() {
		$user = $this->login_manager->get_user();
		if($user !== FALSE)
		{
			$this->login_manager->logout();
		}
		$this->smarty->assign('login_error', $this->session->flashdata('message'));
// 		$user = new User_model();
// 		$this->smarty->assign('user', $user);
		$this->smarty->display('template/backend/login');	
	}
}
/* End of file auth/cpanel.php */
/* Location: ./system/application/controllers/auth/cpanel.php */